const mongoose = require('mongoose')
mongoose.Promise = global.Promise;
const db = require('./config/key').mongoURL;
mongoose.connect(db, { useNewUrlParser: true })
    .then(() => {
        console.log("数据库连接成功");
    })
    .catch(err => {
        console.log(err);
    })
const Schema = mongoose.Schema;
// required 必须输入
// max 最大值
// min
// enum :枚举类型 要求数据必须满足枚举值
// match 增加的数据必须 符合 match的规则
// mixlength 最长度
// minlength: 最小长度
const acticlSchema = new Schema({
    title: {
        type: String,
        required: true
    },
    click: {
        type: Number,
        max: 20
    },
    status: {
        type: String,
        default: "ok", //默认值
        enum: ["ok", "no"] //枚举用在String 类型上

    }
})
const Actric = mongoose.model('Actric', acticlSchema)
Actric({ title: 'veu', click: 19, status: 'no' }).save().then(res => console.log(res))

function getData() {
    Actric.find().then(res => {
        console.log("无数据");

        console.log(res);

    })

}
getData()